/**
 *
 */
package org.yabam.action;

import org.yabam.model.Owner;

import net.sourceforge.stripes.action.ActionBeanContext;

/**
 * Mainly copied/pasted from Bugzooky stripes example. I'll try to think later.
 *
 * @author Tim Fennell
 * @author brisssou
 *
 */
public class YabamActionBeanContext extends ActionBeanContext {

	public static final String LOGGED_OWNER_KEY = "loggedOwner";

	/** Gets the currently logged in user, or null if no-one is logged in. */
	public Owner getLoggedOwner() {
		return (Owner) getRequest().getSession().getAttribute(LOGGED_OWNER_KEY);
	}

	/** Sets the currently logged in user. */
	public void setLoggedOwner(Owner currentUser) {
		getRequest().getSession().setAttribute(LOGGED_OWNER_KEY, currentUser);
	}

	/** Logs the user out by invalidating the session. */
	public void logout() {
		getRequest().getSession().invalidate();
	}

	/**
	 * @see net.sourceforge.stripes.action.ActionBeanContext#toString()
	 */
	@Override
	public String toString() {
		return new StringBuilder().
				append(this.getClass().getSimpleName()).append("{").append(super.toString())
				.append(", loggedOwner=").append(getLoggedOwner()).append("}")
				.toString();
	}
}
